/**
 * Copyright (c) 2016-2019 人人开源 All rights reserved.
 *
 * https://www.babystar.io
 *
 * 版权所有，侵权必究！
 */

package io.babystar.modules.app.controller;

import io.babystar.common.exception.RRException;
import io.babystar.common.utils.ExportFile;
import io.babystar.common.utils.R;
import io.babystar.modules.oss.cloud.OSSFactory;
import io.babystar.modules.oss.entity.SysOssEntity;
import io.babystar.modules.sys.controller.AbstractController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.util.Date;
import java.util.Map;

/**
 * APP登录授权
 *
 * @author Mark sunlightcs@gmail.com
 */
@RestController
@RequestMapping("/applets")
public class AppletsUploadController extends AbstractController{


    /**
     * 上传文件
     */
    @RequestMapping("/upload")
    public R upload(@RequestParam(value = "file", required = false) MultipartFile file, HttpServletResponse response) throws Exception {
        if (file.isEmpty()) {
            throw new RRException("上传文件不能为空");
        }

        byte[] result = file.getBytes();

        // 字节数组转成十六进制
        String str = ExportFile.byte2HexStr(result);
        System.out.println(str);

        return R.ok().put("result", str).put("path",file.getOriginalFilename());
    }

}
